export const createStore = (initData = {}) => (()=>{
    let store = initData;
    const observer = [] // 所有订阅者
    // 获取store
    const getStore = () => store
    // 更新store
    const update = value => {
        if (value !== store) {
            const oldValue = store
            store = value
            // 通知订阅者
            observer.forEach(async cb => await  cb(store, oldValue))
        }

    }
    // 添加订阅者
    const subscribe = cb => observer.push(cb)

    return {
        getStore,
        update,
        subscribe
    }
})()
